package com.wavehi.producer;

import com.rabbitmq.client.Channel;
import com.wavehi.util.RabbitMQFactoryUtils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;

/**
 * @Description 生产者 演示扇出交换机的使用
 * @Author WaveHi
 * @Date 27/12/2021 下午 7:40
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 */
public class Producer_01 {
    //交换机名词
    private static final String EXCHANGE_NAME = "log_exchange";
    public static void main(String[] args) throws Exception {
        //1.获取连接信道
        Channel channel = RabbitMQFactoryUtils.getChannel();
        //2.准备消息
        String message = null;
        Scanner scanner = new Scanner(System.in);
        //3.发送消息
        while(scanner.hasNext()) {
            message = scanner.next();
            channel.basicPublish(EXCHANGE_NAME, "", null,
                    message.getBytes("UTF-8"));
            System.out.printf("Send message %s", message);
        }
    }
}
